<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta charset="UTF-8">
		<title>我的账户-绑定快捷卡</title>
		<jsp:include page="/include/wchat/head.jsp"></jsp:include>

		<link type="text/css" rel="stylesheet"
			href="/v2/wchat/resrc/css/account.css">
	</head>
<style>
.link-touch .items {padding-right:20px;}
.itip ul.items{line-height:20px;}
</style>
	<body>
		<div id="header">
			<a href="javascript:history.go(-1);" class="backto">返回</a>
			<div class="title-sub">
				绑定快捷卡
			</div>
		</div>
		<div id="wrap">
			<form action="/lianPayment.do" method="POST"
				id="lianPaymentForm">
				<div id="bankCardForm">
					<div class="rechange">
						<div class="link-touch">
							<ul class="items">
								<li class="touch">
									<span class="txt">开户姓名</span>
									<span class="value">
										${realName }
										<input type="hidden" name="realName" id="realName" value="${realName }" />
									</span>
								</li>
								<li class="touch">
									<span class="txt">身份证号</span>
									<span class="value">
										${fn:substring(idNo, 0, 6)}********${fn:substring(idNo, 14, 18)}
										<input type="hidden" name="idNo" id="idNo" value="${idNo }" />
									</span>
								</li>
							</ul>
						</div>
						<div class="link-touch">
							<ul class="items">
								<li class="touch">
									<span class="txt">银行</span>
									<select name="bankCheckSelect" id="bankCheckSelect"
										class="select" onchange="setBank();">
										<option value="交通银行_301">
											交通银行
										</option>
										<option value="招商银行_308">
											招商银行
										</option>
										<option value="中国工商银行_102">
											中国工商银行
										</option>
										<option value="中国建设银行_105">
											中国建设银行
										</option>
										<option value="中国银行_104">
											中国银行
										</option>
										<option value="上海浦东发展银行_310">
											上海浦东发展银行
										</option>
										<option value="兴业银行_309">
											兴业银行
										</option>
										<option value="中国农业银行_103">
											中国农业银行
										</option>
										<option value="中国光大银行_303">
											中国光大银行
										</option>
										<option value="广东发展银行_306">
											广东发展银行
										</option>
										<option value="华夏银行_304">
											华夏银行
										</option>
										<option value="平安银行_313">
											平安银行
										</option>
										<option value="中信实业银行_302">
											中信实业银行
										</option>
										<option value="中国民生银行_305">
											中国民生银行
										</option>
									</select>
									<input type="hidden" name="bankCheck" id="bankCheck" value="" />
									<input type="hidden" name="bankId" id="bankId" value="" />
								</li>
								<li class="touch">
									<span class="txt">卡号</span>
									<input class="input" id="bankCardNumber" name="bankCardNumber"
										placeholder="银行卡号">
									<input class="input" id="tranAmt" name="tranAmt"
										value="${tranAmt }" type="hidden">
								</li>
							</ul>

							<div id="errorTip" class="vtip errs">
							</div>
						</div>
					</div>
					<div class="operate-button">
						<a href="javascript:void(0)" id="submit" class="btn">下一步</a>
					</div>

				</div>
			</form>
			<div id="itip" class="itip">
				<div class="title">
					<h2>
						说明：
					</h2>
				</div>
				<div>
					<ul class="items">
						<li>
							1. 每个用户<span class="light-org">只能绑定一张银行卡作为快捷卡</span>（以下称之为“快捷卡”），<span class="light-org">请选择常用银行卡进行绑定，且一旦绑定后，也只可以提现到快捷卡</span>；
						</li>
						<li>
							2.
							提现时，如已绑定快捷卡，不需重新绑定；如尚未绑定，<span class="light-org">请先绑定快捷卡作为提现卡</span>，同时其他绑定的提现银行卡将失效。<span class="light-org">提现申请时选择非快捷卡，提现将失败</span>；
						</li>
						<li>
							3. 为保障您账户资金的安全，<span class="light-org">如需换绑其他银行卡，需审核您的资料</span>，请联系共富网客服，提供相关资料；
						</li>
						<li>
							4. 客服确认信息及身份后，解除绑定，用户可从前台页面自行再次发起快捷绑卡及提现绑卡操作；
						</li>
						<li>
							5. 点击"下一步"按钮，<span class="light-org">表示您已经仔细阅读并同意此说明</span>。
						</li>
					</ul>
				</div>
			</div>

		</div>
		<jsp:include page="/include/wchat/footer.jsp"></jsp:include>

		<script type="text/javascript">
	$(function() {
		setBank();
		$("#submit").click(function() {
			addnewcard();
		});

	});

	function setBank() {
		var bankName = $("#bankCheckSelect").val();
		var strs = $.trim(bankName.slice(0, -4));
		var code = $.trim(bankName.slice(-3));
		$("#bankCheck").val(strs);
		$("#bankId").val(code);
	}

	function addnewcard() {
		var bankCard = $.trim($("#bankCardNumber").val());
		if (cardNoCheck(bankCard)) {
			var param = {}
			param["paramMap.bankName"] = $("#bankCheck").val(); //开户行
			param["paramMap.bankId"] = $("#bankId").val(); //开户行ID
			param["paramMap.bankCard"] = $.trim($("#bankCardNumber").val()); //卡号
			$.ajax( {
				dataType : 'json',
				url : environment.basePath + "/lianPayBindBankCard.do",
				data : param,
				type : 'POST',
				beforeSend : function() {
					$('#errorTip').html("");
				},
				success : function(data) {
					if (data.msg == "noLogin") {
						window.location.href = "/wchatIndex.do";
					} else if (data.msg == "queryFail") {
						$('#errorTip').html("*银行卡BIN信息核对失败，请稍后重试");
					} else if (data.msg == "bankCodeError") {
						$('#errorTip').html("*您选择的银行与输入的银行卡号不对应，请核对后重试");
					} else if (data.msg == "success") {
						$("#lianPaymentForm").submit();
					}
				},
				error : function(data,status, e) {
					$('#errorTip').html("*绑定快捷卡失败，请稍后重试");
				}
			});
		}

	}

	function cardNoCheck(bankno) {
		if (bankno == "" || bankno == null) {
			$('#errorTip').html("*卡号输入不正确，请检查");
			return false;
		}
		var lastNum = bankno.substr(bankno.length - 1, 1);

		var first15Num = bankno.substr(0, bankno.length - 1);
		var newArr = new Array();
		for ( var i = first15Num.length - 1; i > -1; i--) {
			newArr.push(first15Num.substr(i, 1));
		}
		var arrJiShu = new Array();
		var arrJiShu2 = new Array();

		var arrOuShu = new Array();
		for ( var j = 0; j < newArr.length; j++) {
			if ((j + 1) % 2 == 1) {
				if (parseInt(newArr[j]) * 2 < 9)
					arrJiShu.push(parseInt(newArr[j]) * 2);
				else
					arrJiShu2.push(parseInt(newArr[j]) * 2);
			} else
				arrOuShu.push(newArr[j]);
		}

		var jishu_child1 = new Array();
		var jishu_child2 = new Array();
		for ( var h = 0; h < arrJiShu2.length; h++) {
			jishu_child1.push(parseInt(arrJiShu2[h]) % 10);
			jishu_child2.push(parseInt(arrJiShu2[h]) / 10);
		}

		var sumJiShu = 0;
		var sumOuShu = 0;
		var sumJiShuChild1 = 0;
		var sumJiShuChild2 = 0;
		var sumTotal = 0;
		for ( var m = 0; m < arrJiShu.length; m++) {
			sumJiShu = sumJiShu + parseInt(arrJiShu[m]);
		}

		for ( var n = 0; n < arrOuShu.length; n++) {
			sumOuShu = sumOuShu + parseInt(arrOuShu[n]);
		}

		for ( var p = 0; p < jishu_child1.length; p++) {
			sumJiShuChild1 = sumJiShuChild1 + parseInt(jishu_child1[p]);
			sumJiShuChild2 = sumJiShuChild2 + parseInt(jishu_child2[p]);
		}
		sumTotal = parseInt(sumJiShu) + parseInt(sumOuShu)
				+ parseInt(sumJiShuChild1) + parseInt(sumJiShuChild2);

		var k = parseInt(sumTotal) % 10 == 0 ? 10 : parseInt(sumTotal) % 10;
		var luhm = 10 - k;

		if (parseInt(sumJiShu) + parseInt(sumOuShu) == 0) {
			$("#errorTip").html("*卡号输入不正确，请检查").show();
			return false;
		}

		if (lastNum == luhm) {
			return true;
		} else {
			$("#errorTip").html("*卡号输入不正确，请检查").show();
			return false;
		}
	}
</script>

	</body>
</html>